var dbConfig = require('../dbconfig');
var mysql = require('mysql');  
var pool  = mysql.createPool({  
  connectionLimit : 10,  
  host            : dbConfig.mysql2.host,  
  user            : dbConfig.mysql2.user,  
  password        : dbConfig.mysql2.password, 
  database        : dbConfig.mysql2.database
}); 
module.exports = {
    query: function(sql,array,callback)
    {
        if (!sql) {  
            callback({msg:"错误操作",status:105});  
            return;  
        }
        pool.getConnection(function(err, connection){
            if(err)
            {
                callback({msg:"数据库连接失败",status:101});
            }else{
                connection.query(sql, array, function(err, rows) {
                    if (err) {  console.log(err);
                      callback({msg:"查询失败",status:102});  
                      return;  
                    };  
                    callback({msg:"操作成功",status:100,data:{
                        rows:rows
                    }});
                    
                });  
            }
            connection.release();
        });  
        
    }
}